package com.zp.datax.core;

import com.zp.datax.core.model.DataxJobTrigger;

import java.util.Objects;

/**
 * id条件处理器
 *
 * @author bruce
 * @date 2019-07-15
 */
public class EndIdCondition extends Condition {

    protected EndIdCondition(Condition condition) {
        super(condition);
    }

    @Override
    public Object[] append(String str) {

        Object[] objarray = getObjarray(str);
        String condition = Objects.toString(objarray[0]);

        DataxJobTrigger dataxJobTrigger = getDataxJobTrigger();
        Integer range = dataxJobTrigger.getRange();
        Integer unit = dataxJobTrigger.getUnit();

        if (range.compareTo(0) == 1
                && unit.compareTo(7) == 0
                && str.contains("startId")) {
            Long maxid = dataxJobTrigger.getMaxid() + range;
            objarray[0] = String.format("%sendId=%d,", condition, maxid);
            dataxJobTrigger.setMaxid(maxid);
        }

        return objarray;
    }
}
